<!DOCTYPE html>



  


<html class="theme-next pisces use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />







<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.4" rel="stylesheet" type="text/css" />


  <link rel="apple-touch-icon" sizes="180x180" href="/agul.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/agul.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/agul.png?v=5.1.4">






  <meta name="keywords" content="jQuery 笔记," />




  


  <link rel="alternate" href="/atom.xml" title="Agul'blog" type="application/atom+xml" />






<meta name="description" content="jQueryjQuery简介JavaScript库的概念JavaScript开发的过程中，处理浏览器的兼容很复杂而且很耗时，于是一些封装了这些操作的库应运而生。这些库还会把一些常用的代码进行封装。 把一些常用到的方法写到一个单独的js文件，使用的时候直接去引用这js文件就可以了。（animate.js、common.js） 常见的JavaScript 库 - jQuery、Prototype、Mo">
<meta property="og:type" content="article">
<meta property="og:title" content="jQuery">
<meta property="og:url" content="https://ultraman-agul.github.io/2020/05/10/09jQuery/index.html">
<meta property="og:site_name" content="Agul&#39;blog">
<meta property="og:description" content="jQueryjQuery简介JavaScript库的概念JavaScript开发的过程中，处理浏览器的兼容很复杂而且很耗时，于是一些封装了这些操作的库应运而生。这些库还会把一些常用的代码进行封装。 把一些常用到的方法写到一个单独的js文件，使用的时候直接去引用这js文件就可以了。（animate.js、common.js） 常见的JavaScript 库 - jQuery、Prototype、Mo">
<meta property="article:published_time" content="2020-05-10T00:51:40.000Z">
<meta property="article:modified_time" content="2020-05-10T01:53:42.579Z">
<meta property="article:author" content="agul">
<meta property="article:tag" content="jQuery 笔记">
<meta name="twitter:card" content="summary">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Pisces',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="https://ultraman-agul.github.io/2020/05/10/09jQuery/"/>





  <title>jQuery | Agul'blog</title>
  








<meta name="generator" content="Hexo 4.2.0"></head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">Agul'blog</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle">Record a good life</p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="https://ultraman-agul.github.io/2020/05/10/09jQuery/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="agul">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/agul1.png">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Agul'blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">jQuery</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2020-05-10T08:51:40+08:00">
                2020-05-10
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/jQuery/" itemprop="url" rel="index">
                    <span itemprop="name">jQuery</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <h1 id="jQuery"><a href="#jQuery" class="headerlink" title="jQuery"></a>jQuery</h1><h2 id="jQuery简介"><a href="#jQuery简介" class="headerlink" title="jQuery简介"></a>jQuery简介</h2><h3 id="JavaScript库的概念"><a href="#JavaScript库的概念" class="headerlink" title="JavaScript库的概念"></a>JavaScript库的概念</h3><p>JavaScript开发的过程中，处理浏览器的兼容很复杂而且很耗时，于是一些封装了这些操作的库应运而生。这些库还会把一些常用的代码进行封装。</p>
<p>把一些常用到的方法写到一个单独的js文件，使用的时候直接去引用这js文件就可以了。（animate.js、common.js）</p>
<p>常见的JavaScript 库 - jQuery、Prototype、MooTools。其中jQuery是最常用的一个</p>
<p>jQuery其实就是一个js文件，里面封装了一大堆的方法方便我们的开发，其实就是一个加强版的common.js，学习jQuery，其实就是学习jQuery这个js文件中封装的一大堆方法。</p>
<p>目标：</p>
<ul>
<li><p>掌握编程jQuery的基本使用</p>
<ul>
<li>掌握jQuery插件的使用</li>
<li>能够开发jQuery插件</li>
<li>选择器、属性操作、样式操作、节点操作、动画、事件、插件</li>
</ul>
</li>
</ul>
<h3 id="jQuery的优点好处"><a href="#jQuery的优点好处" class="headerlink" title="jQuery的优点好处"></a>jQuery的优点好处</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">jQuery设计的宗旨是&#39;Write Less，Do More&#39;，即倡导写更少的代码，做更多的事情（事半功倍）。它封装JavaScript常用的功能代码，提供一种简便的操作，优化HTML文档操作、事件处理、动画设计和Ajax交互。</span><br><span class="line">jQuery的核心特性可以总结为：具有独特的链式语法和短小清晰的多功能接口；具有高效灵活的css选择器，并且可对CSS选择器进行扩展；拥有便捷的插件扩展机制和丰富的插件。jQuery兼容各种主流浏览器。</span><br><span class="line">极大地简化了 JavaScript 编程。</span><br></pre></td></tr></table></figure>



<p>[jQuery官网](http:// jquery.com)</p>
<h3 id="体验jQuery"><a href="#体验jQuery" class="headerlink" title="体验jQuery"></a>体验jQuery</h3><p>使用JavaScript开发过程中，有许多不便之处</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">-查找元素的方法太少，麻烦。</span><br><span class="line">-遍历伪数组很麻烦，通常要嵌套一大堆的<span class="keyword">for</span>循环。</span><br><span class="line">-有兼容性问题。</span><br><span class="line">-想要实现简单的动画效果，也很麻烦</span><br><span class="line">-代码冗余。</span><br></pre></td></tr></table></figure>

<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">$(<span class="built_in">document</span>).ready(<span class="function"><span class="keyword">function</span> (<span class="params"></span>) </span>&#123;  <span class="comment">//页面加载函数</span></span><br><span class="line">    $(<span class="string">'#btn1'</span>).click(<span class="function"><span class="keyword">function</span> (<span class="params"></span>) </span>&#123;</span><br><span class="line">      	<span class="comment">// 隐式迭代：偷偷的遍历，在jQuery中，不需要手动写for循环了，会自动进行遍历。</span></span><br><span class="line">        $(<span class="string">'div'</span>).show(<span class="number">200</span>);</span><br><span class="line">    &#125;);</span><br><span class="line"></span><br><span class="line">    $(<span class="string">'#btn2'</span>).click(<span class="function"><span class="keyword">function</span> (<span class="params"></span>) </span>&#123;</span><br><span class="line">        $(<span class="string">'div'</span>).text(<span class="string">'我是内容'</span>); <span class="comment">// 设置文本内容</span></span><br><span class="line">    &#125;);</span><br><span class="line">&#125;);</span><br></pre></td></tr></table></figure>

<p>优点总结：</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">-查找元素的方法多种多样，非常灵活</span><br><span class="line">-拥有隐式迭代特性，因此不再需要手写<span class="keyword">for</span>循环了。</span><br><span class="line">-完全没有兼容性问题。</span><br><span class="line">-实现动画非常简单，而且功能更加的强大。</span><br><span class="line">-代码简单、粗暴。</span><br></pre></td></tr></table></figure>

<h3 id="jQuery中顶级对象"><a href="#jQuery中顶级对象" class="headerlink" title="jQuery中顶级对象"></a>jQuery中顶级对象</h3><p>jQuery中的顶级对象是$或jQuery</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">获取jQuery对象</span><br><span class="line">入口函数</span><br><span class="line">高级功能</span><br></pre></td></tr></table></figure>

<p>注意：jQuery中的$和JQuery关键字本身为同一对象</p>
<h3 id="jQuery中页面加载事件"><a href="#jQuery中页面加载事件" class="headerlink" title="jQuery中页面加载事件"></a>jQuery中页面加载事件</h3><p>使用jQuery的三个步骤：</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">引入jQuery文件</span><br><span class="line">入口函数</span><br><span class="line">功能实现</span><br></pre></td></tr></table></figure>

<p>关于jQuery的入口函数：</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 第一种写法</span></span><br><span class="line">$(<span class="built_in">document</span>).ready(<span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line">	xxx</span><br><span class="line">&#125;);</span><br><span class="line"><span class="comment">// 第二种写法</span></span><br><span class="line">$(<span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line">	xxx</span><br><span class="line">&#125;);</span><br></pre></td></tr></table></figure>

<p>jQuery入口函数与window.onload的对比</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">JavaScript的入口函数要等到页面中所有资源（包括图片、文件）加载完成才开始执行。</span><br><span class="line">jQuery的入口函数只会等待文档树加载完成就开始执行，并不会等待图片、文件的加载。<span class="comment">//较快进行加载</span></span><br></pre></td></tr></table></figure>

<h2 id="jQuery对象和DOM对象"><a href="#jQuery对象和DOM对象" class="headerlink" title="jQuery对象和DOM对象"></a>jQuery对象和DOM对象</h2><h3 id="jQuery对象和DOM对象的区别"><a href="#jQuery对象和DOM对象的区别" class="headerlink" title="jQuery对象和DOM对象的区别"></a>jQuery对象和DOM对象的区别</h3><h4 id="DOM对象"><a href="#DOM对象" class="headerlink" title="DOM对象"></a>DOM对象</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">用原生JavaScript获取的DOM对象</span><br><span class="line">	通过document.getElementById()  反馈的是元素(DOM对象)</span><br><span class="line">通过document.getElementsByTagName()获取到的是什么？</span><br><span class="line">	伪数组(集合)，集合中的每一个对象是DOM对象</span><br></pre></td></tr></table></figure>

<h4 id="jQuery对象"><a href="#jQuery对象" class="headerlink" title="jQuery对象"></a>jQuery对象</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">jQuery对象用$()的方式获取的对象</span><br><span class="line">jQuery对象又可以叫做包装集(包装的DOM对象的集合)</span><br></pre></td></tr></table></figure>

<h4 id="区别"><a href="#区别" class="headerlink" title="区别"></a>区别</h4><p>jQuery对象不能使用DOM对象的成员，DOM对象不能使用jQuery对象的成员</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// DOM对象</span></span><br><span class="line"><span class="keyword">var</span> box = <span class="built_in">document</span>.getElementById(<span class="string">'box'</span>);</span><br><span class="line"><span class="comment">// 错误</span></span><br><span class="line">box.text(<span class="string">'hello'</span>);</span><br><span class="line"><span class="comment">// 正确</span></span><br><span class="line">box.innerText = <span class="string">'hello'</span>;</span><br><span class="line"></span><br><span class="line"><span class="comment">// jQuery对象，jQuery对象加前缀$，用以区分DOM对象</span></span><br><span class="line"><span class="keyword">var</span> $box = $(<span class="string">'#box'</span>);</span><br><span class="line"><span class="comment">// 错误</span></span><br><span class="line">$box.innerText = <span class="string">'hello'</span>;</span><br><span class="line"><span class="comment">// 正确</span></span><br><span class="line">$box.text(<span class="string">'hello'</span>);</span><br></pre></td></tr></table></figure>

<h3 id="jQuery对象和DOM对象的相互转换"><a href="#jQuery对象和DOM对象的相互转换" class="headerlink" title="jQuery对象和DOM对象的相互转换"></a>jQuery对象和DOM对象的相互转换</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">jQuery对象转换成DOM对象：   </span><br><span class="line">	jQuery对象.get(索引值); </span><br><span class="line">	jQuery对象[索引值] </span><br><span class="line">    	jQuery对象是包装集(集合)，从集合中取数据可以使用索引的方式</span><br><span class="line">DOM对象转换成jQuery对象：   </span><br><span class="line">	$(DOM对象) 只有这一种方法;</span><br></pre></td></tr></table></figure>



<h2 id="选择器"><a href="#选择器" class="headerlink" title="选择器"></a>选择器</h2><p>jQuery选择器是jQuery为我们提供的一组方法，让我们更加方便的获取到页面中的元素。注意：jQuery选择器返回的是jQuery对象。</p>
<p>jQuery选择器有很多，基本兼容了CSS1到CSS3所有的选择器，并且jQuery还添加了很多更加复杂的选择器。</p>
<p>jQuery选择器虽然很多，但是选择器之间可以相互替代，就是说获取一个元素，会有很多种方法获取到。所以我们平时真正能用到的只是少数的最常用的选择器。</p>
<h3 id="jQuery基本选择器"><a href="#jQuery基本选择器" class="headerlink" title="jQuery基本选择器"></a>jQuery基本选择器</h3><table>
<thead>
<tr>
<th>名称</th>
<th>用法</th>
<th align="left">描述</th>
</tr>
</thead>
<tbody><tr>
<td>ID选择器</td>
<td>$(‘#id’);</td>
<td align="left">获取指定ID的元素</td>
</tr>
<tr>
<td>类选择器</td>
<td>$(‘.class’);</td>
<td align="left">获取同一类class的元素</td>
</tr>
<tr>
<td>标签选择器</td>
<td>$(‘div’);</td>
<td align="left">获取同一类标签的所有元素</td>
</tr>
<tr>
<td>并集选择器</td>
<td>$(‘div,p,li’);</td>
<td align="left">使用逗号分隔，只要符合条件之一就可。</td>
</tr>
<tr>
<td>交集选择器</td>
<td>$(‘div.redClass’);</td>
<td align="left">获取class为redClass的div元素</td>
</tr>
</tbody></table>
<ul>
<li>总结：跟css的选择器用法一模一样。</li>
</ul>
<h3 id="jQuery层级选择器"><a href="#jQuery层级选择器" class="headerlink" title="jQuery层级选择器"></a>jQuery层级选择器</h3><table>
<thead>
<tr>
<th>名称</th>
<th>用法</th>
<th align="left">描述</th>
</tr>
</thead>
<tbody><tr>
<td>子代选择器</td>
<td>$(‘ul &gt; li’);</td>
<td align="left">使用-号，获取儿子层级的元素，注意，并不会获取孙子层级的元素</td>
</tr>
<tr>
<td>后代选择器</td>
<td>$(‘ul li’);</td>
<td align="left">使用空格，代表后代选择器，获取ul下的所有li元素，包括孙子等</td>
</tr>
</tbody></table>
<ul>
<li>跟CSS的选择器一模一样。</li>
</ul>
<h3 id="jQuery过滤选择器"><a href="#jQuery过滤选择器" class="headerlink" title="jQuery过滤选择器"></a>jQuery过滤选择器</h3><ul>
<li>这类选择器都带冒号:</li>
</ul>
<table>
<thead>
<tr>
<th>名称</th>
<th>用法</th>
<th align="left">描述</th>
</tr>
</thead>
<tbody><tr>
<td>:eq（index）</td>
<td>$(‘li:eq(2)’).css(‘color’, ‘red’);</td>
<td align="left">获取到的li元素中，选择索引号为2的元素，索引号index从0开始。</td>
</tr>
<tr>
<td>:odd</td>
<td>$(‘li:odd’).css(‘color’, ‘red’);</td>
<td align="left">获取到的li元素中，选择索引号为奇数的元素</td>
</tr>
<tr>
<td>:even</td>
<td>$(‘li:even’).css(‘color’, ‘red’);</td>
<td align="left">获取到的li元素中，选择索引号为偶数的元素</td>
</tr>
</tbody></table>
<h3 id="jQuery筛选选择器-方法"><a href="#jQuery筛选选择器-方法" class="headerlink" title="jQuery筛选选择器(方法)"></a>jQuery筛选选择器(方法)</h3><ul>
<li>筛选选择器的功能与过滤选择器有点类似，但是用法不一样，筛选选择器主要是方法。</li>
</ul>
<table>
<thead>
<tr>
<th>名称</th>
<th>用法</th>
<th align="left">描述</th>
</tr>
</thead>
<tbody><tr>
<td>children(selector)</td>
<td>$(‘ul’).children(‘li’)</td>
<td align="left">相当于$(‘ul-li’)，子类选择器</td>
</tr>
<tr>
<td>find(selector)</td>
<td>$(‘ul’).find(‘li’);</td>
<td align="left">相当于$(‘ul li’),后代选择器</td>
</tr>
<tr>
<td>siblings(selector)</td>
<td>$(‘#first’).siblings(‘li’);</td>
<td align="left">查找兄弟节点，不包括自己本身。</td>
</tr>
<tr>
<td>parent()</td>
<td>$(‘#first’).parent();</td>
<td align="left">查找父亲</td>
</tr>
<tr>
<td>eq(index)</td>
<td>$(‘li’).eq(2);</td>
<td align="left">相当于$(‘li:eq(2)’),index从0开始</td>
</tr>
<tr>
<td>next()</td>
<td>$(‘li’).next()</td>
<td align="left">找下一个兄弟</td>
</tr>
<tr>
<td>prev()</td>
<td>$(‘li’).prev()</td>
<td align="left">找上一次兄弟</td>
</tr>
</tbody></table>
<h2 id="jQuery操作样式"><a href="#jQuery操作样式" class="headerlink" title="jQuery操作样式"></a>jQuery操作样式</h2><h3 id="CSS操作"><a href="#CSS操作" class="headerlink" title="CSS操作"></a>CSS操作</h3><ul>
<li><p>功能：设置或者修改样式，操作的是style属性。</p>
</li>
<li><p>操作单个样式</p>
</li>
</ul>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// name：需要设置的样式名称</span></span><br><span class="line"><span class="comment">// value：对应的样式值</span></span><br><span class="line">$obj.css(name, value);</span><br><span class="line"><span class="comment">// 使用案例</span></span><br><span class="line">$(<span class="string">'#one'</span>).css(<span class="string">'background'</span>,<span class="string">'gray'</span>);<span class="comment">// 将背景色修改为灰色</span></span><br></pre></td></tr></table></figure>

<ul>
<li>设置多个样式，用对象</li>
</ul>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 参数是一个对象，对象中包含了需要设置的样式名和样式值</span></span><br><span class="line">$obj.css(obj);</span><br><span class="line"><span class="comment">// 使用案例</span></span><br><span class="line">$(<span class="string">'#one'</span>).css(&#123;</span><br><span class="line">    <span class="string">'background'</span>:<span class="string">'gray'</span>,</span><br><span class="line">    <span class="string">'width'</span>:<span class="string">'400px'</span>,</span><br><span class="line">    <span class="string">'height'</span>:<span class="string">'200px'</span></span><br><span class="line">&#125;);</span><br></pre></td></tr></table></figure>

<ul>
<li>获取样式</li>
</ul>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// name:需要获取的样式名称</span></span><br><span class="line">$obj.css(name);</span><br><span class="line"><span class="comment">// 案例</span></span><br><span class="line">$(<span class="string">'div'</span>).css(<span class="string">'background-color'</span>);</span><br></pre></td></tr></table></figure>

<p>注意：<strong>获取</strong>样式操作只会返回<strong>第一个</strong>元素对应的样式值。</p>
<p>隐式迭代：</p>
<ol>
<li>设置操作的时候，如果是多个元素，那么给所有的元素设置相同的值</li>
<li>获取操作的时候，如果是多个元素，那么只会返回第一个元素的值。</li>
</ol>
<h3 id="class操作"><a href="#class操作" class="headerlink" title="class操作"></a>class操作</h3><ul>
<li>添加样式类</li>
</ul>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// name：需要添加的样式类名，注意参数不要带点.</span></span><br><span class="line">$obj.addClass(name);</span><br><span class="line"><span class="comment">// 例子,给所有的div添加one的样式。</span></span><br><span class="line">$(<span class="string">'div'</span>).addClass(<span class="string">'one'</span>);</span><br></pre></td></tr></table></figure>

<ul>
<li>移除样式类</li>
</ul>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// name:需要移除的样式类名</span></span><br><span class="line">$obj.removeClass(<span class="string">'name'</span>);</span><br><span class="line"><span class="comment">// 例子，移除div中one的样式类名</span></span><br><span class="line">$(<span class="string">'div'</span>).removeClass(<span class="string">'one'</span>);</span><br></pre></td></tr></table></figure>

<ul>
<li>判断是否有某个样式类</li>
</ul>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// name:用于判断的样式类名，返回值为true false</span></span><br><span class="line">$obj.hasClass(name)</span><br><span class="line"><span class="comment">// 例子，判断第一个div是否有one的样式类</span></span><br><span class="line">$(<span class="string">'div'</span>).hasClass(<span class="string">'one'</span>);</span><br></pre></td></tr></table></figure>

<ul>
<li>切换样式类</li>
</ul>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// name:需要切换的样式类名，如果有，移除该样式，如果没有，添加该样式。</span></span><br><span class="line">$obj.toggleClass(name);</span><br><span class="line"><span class="comment">// 例子</span></span><br><span class="line">$(<span class="string">'div'</span>).toggleClass(<span class="string">'one'</span>);</span><br></pre></td></tr></table></figure>

<ul>
<li>tab栏切换案例 </li>
</ul>
<h2 id="jQuery动画"><a href="#jQuery动画" class="headerlink" title="jQuery动画"></a>jQuery动画</h2><ul>
<li>jQuery提供了三组基本动画，这些动画都是标准的、有规律的效果，jQuery还提供了自定义动画的功能。</li>
</ul>
<h3 id="三组基本动画"><a href="#三组基本动画" class="headerlink" title="三组基本动画"></a>三组基本动画</h3><ul>
<li>显示(show)与隐藏(hide)是一组动画：</li>
<li>滑入(slideUp)与滑出(slideDown)与切换(slideToggle)，效果与卷帘门类似</li>
<li>淡入(fadeIn)与淡出(fadeOut)与切换(fadeToggle)</li>
</ul>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">$obj.show([speed], [callback]);</span><br><span class="line"><span class="comment">// speed(可选)：动画的执行时间</span></span><br><span class="line">	 <span class="comment">// 1.如果不传，就没有动画效果。如果是slide和fade系列，会默认为normal</span></span><br><span class="line">	 <span class="comment">// 2.毫秒值(比如1000),动画在1000毫秒执行完成(推荐)</span></span><br><span class="line">     <span class="comment">// 3.固定字符串，slow(200)、normal(400)、fast(600)，如果传其他字符串，则默认为normal。</span></span><br><span class="line"><span class="comment">// callback(可选):执行完动画后执行的回调函数</span></span><br><span class="line"></span><br><span class="line">slideDown()/slideUp()/slideToggle();同理</span><br><span class="line">fadeIn()/fadeOut();fadeToggle();同理</span><br></pre></td></tr></table></figure>

<h3 id="自定义动画"><a href="#自定义动画" class="headerlink" title="自定义动画"></a>自定义动画</h3><ul>
<li>animate: 自定义动画</li>
</ul>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">$(selector).animate(&#123;params&#125;,[speed],[easing],[callback]);</span><br><span class="line"><span class="comment">// &#123;params&#125;：要执行动画的CSS属性，带数字（必选）</span></span><br><span class="line"><span class="comment">// speed：执行动画时长（可选）</span></span><br><span class="line"><span class="comment">// easing:执行效果，默认为swing（缓动）  可以是linear（匀速）</span></span><br><span class="line"><span class="comment">// callback：动画执行完后立即执行的回调函数（可选）</span></span><br></pre></td></tr></table></figure>

<h3 id="动画队列与停止动画"><a href="#动画队列与停止动画" class="headerlink" title="动画队列与停止动画"></a>动画队列与停止动画</h3><ul>
<li>在同一个元素上执行多个动画，那么对于这个动画来说，后面的动画会被放到动画队列中，等前面的动画执行完成了才会执行</li>
</ul>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// stop方法：停止动画效果</span></span><br><span class="line">stop(clearQueue, jumpToEnd);</span><br><span class="line"><span class="comment">// 第一个参数：是否清除队列</span></span><br><span class="line"><span class="comment">// 第二个参数：是否跳转到最终效果</span></span><br></pre></td></tr></table></figure>

<h3 id=""><a href="#" class="headerlink" title=""></a></h3><h2 id="jQuery节点操作"><a href="#jQuery节点操作" class="headerlink" title="jQuery节点操作"></a>jQuery节点操作</h2><h3 id="创建节点"><a href="#创建节点" class="headerlink" title="创建节点"></a>创建节点</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// $(htmlStr)</span></span><br><span class="line"><span class="comment">// htmlStr：html格式的字符串</span></span><br><span class="line">$(<span class="string">'&lt;span-这是一个span元素&lt;/span-'</span>);</span><br></pre></td></tr></table></figure>

<h3 id="添加节点"><a href="#添加节点" class="headerlink" title="添加节点"></a>添加节点</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">append  appendTo	在被选元素的结尾插入内容</span><br><span class="line">prepend prependTo	在被选元素的开头插入内容</span><br><span class="line">before				在被选元素之前插入内容</span><br><span class="line">after				在被选元素之后插入内容</span><br></pre></td></tr></table></figure>

<h3 id="清空节点与删除节点"><a href="#清空节点与删除节点" class="headerlink" title="清空节点与删除节点"></a>清空节点与删除节点</h3><ul>
<li>empty：清空指定节点的所有元素，自身保留(清理门户)</li>
</ul>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">$(<span class="string">'div'</span>).empty(); <span class="comment">// 清空div的所有内容（推荐使用，会清除子元素上绑定的内容，源码）</span></span><br><span class="line">$(<span class="string">'div'</span>).html(<span class="string">''</span>);<span class="comment">// 使用html方法来清空元素，不推荐使用，会造成内存泄漏，绑定的事件不会被清除。</span></span><br></pre></td></tr></table></figure>

<ul>
<li>remove：相比于empty，自身也删除（自杀）</li>
</ul>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$(<span class="string">'div'</span>).remove();</span><br></pre></td></tr></table></figure>



<h3 id="克隆节点"><a href="#克隆节点" class="headerlink" title="克隆节点"></a>克隆节点</h3><ul>
<li>作用：复制匹配的元素</li>
</ul>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 复制$(selector)所匹配到的元素（深度复制）</span></span><br><span class="line"><span class="comment">// cloneNode(true)</span></span><br><span class="line"><span class="comment">// 返回值为复制的新元素，和原来的元素没有任何关系了。即修改新元素，不会影响到原来的元素。</span></span><br><span class="line">$(selector).clone();</span><br></pre></td></tr></table></figure>

<h3 id="-1"><a href="#-1" class="headerlink" title=""></a></h3><h2 id="jQuery操作属性"><a href="#jQuery操作属性" class="headerlink" title="jQuery操作属性"></a>jQuery操作属性</h2><h3 id="attr操作"><a href="#attr操作" class="headerlink" title="attr操作"></a>attr操作</h3><ul>
<li>设置单个属性</li>
</ul>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 第一个参数：需要设置的属性名</span></span><br><span class="line"><span class="comment">// 第二个参数：对应的属性值</span></span><br><span class="line">$obj.attr(name, value);</span><br><span class="line"><span class="comment">// 用法举例</span></span><br><span class="line">$(<span class="string">'img'</span>).attr(<span class="string">'title'</span>,<span class="string">'哎哟，不错哦'</span>);</span><br><span class="line">$(<span class="string">'img'</span>).attr(<span class="string">'alt'</span>,<span class="string">'哎哟，不错哦'</span>);</span><br></pre></td></tr></table></figure>

<ul>
<li>设置多个属性</li>
</ul>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 参数是一个对象，包含了需要设置的属性名和属性值</span></span><br><span class="line">$obj.attr(obj)</span><br><span class="line"><span class="comment">// 用法举例</span></span><br><span class="line">$(<span class="string">'img'</span>).attr(&#123;</span><br><span class="line">    title:<span class="string">'哎哟，不错哦'</span>,</span><br><span class="line">    alt:<span class="string">'哎哟，不错哦'</span>,</span><br><span class="line">    style:<span class="string">'opacity:.5'</span></span><br><span class="line">&#125;);</span><br></pre></td></tr></table></figure>

<ul>
<li>获取属性</li>
</ul>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 传需要获取的属性名称，返回对应的属性值</span></span><br><span class="line">$obj.attr(name)</span><br><span class="line"><span class="comment">// 用法举例</span></span><br><span class="line"><span class="keyword">var</span> oTitle = $(<span class="string">'img'</span>).attr(<span class="string">'title'</span>);</span><br><span class="line">alert(oTitle);</span><br></pre></td></tr></table></figure>

<ul>
<li>移除属性</li>
</ul>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 参数：需要移除的属性名，</span></span><br><span class="line">$obj.removeAttr(name);</span><br><span class="line"><span class="comment">// 用法举例</span></span><br><span class="line">$(<span class="string">'img'</span>).removeAttr(<span class="string">'title'</span>);</span><br></pre></td></tr></table></figure>

<h3 id="prop操作"><a href="#prop操作" class="headerlink" title="prop操作"></a>prop操作</h3><ul>
<li>在jQuery1.6之后，对于checked、selected、disabled这类<strong>boolean类型的属性</strong>来说，不能用attr方法，只能用prop方法。</li>
</ul>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 设置属性</span></span><br><span class="line">$(<span class="string">':checked'</span>).prop(<span class="string">'checked'</span>,<span class="literal">true</span>);</span><br><span class="line"><span class="comment">// 获取属性</span></span><br><span class="line">$(<span class="string">':checked'</span>).prop(<span class="string">'checked'</span>);<span class="comment">// 返回true或者false</span></span><br></pre></td></tr></table></figure>

<h3 id="val-text-html"><a href="#val-text-html" class="headerlink" title="val()/text/()html()"></a>val()/text/()html()</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">$obj.val()		获取或者设置表单元素的value属性的值</span><br><span class="line">$obj.html() 	对应innerHTML</span><br><span class="line">$obj.text()		对应innerText/textContent，处理了浏览器的兼容性</span><br></pre></td></tr></table></figure>

<h3 id="-2"><a href="#-2" class="headerlink" title=""></a></h3><h2 id="jQuery尺寸和位置操作"><a href="#jQuery尺寸和位置操作" class="headerlink" title="jQuery尺寸和位置操作"></a>jQuery尺寸和位置操作</h2><h3 id="width方法与height方法"><a href="#width方法与height方法" class="headerlink" title="width方法与height方法"></a>width方法与height方法</h3><ul>
<li>设置或者获取高度，不包括内边距、边框和外边距</li>
</ul>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 带参数表示设置高度</span></span><br><span class="line">$(<span class="string">'img'</span>).height(<span class="number">200</span>);</span><br><span class="line"><span class="comment">// 不带参数获取高度</span></span><br><span class="line">$(<span class="string">'img'</span>).height();</span><br></pre></td></tr></table></figure>

<p>获取网页的可视区宽高</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 获取可视区宽度</span></span><br><span class="line">$(<span class="built_in">window</span>).width();</span><br><span class="line"><span class="comment">// 获取可视区高度</span></span><br><span class="line">$(<span class="built_in">window</span>).height();</span><br></pre></td></tr></table></figure>

<h3 id="innerWidth-innerHeight-outerWidth-outerHeight"><a href="#innerWidth-innerHeight-outerWidth-outerHeight" class="headerlink" title="innerWidth/innerHeight/outerWidth/outerHeight"></a>innerWidth/innerHeight/outerWidth/outerHeight</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">innerWidth()/innerHeight()	方法返回元素的宽度/高度（包括内边距）。</span><br><span class="line">outerWidth()/outerHeight()  方法返回元素的宽度/高度（包括内边距和边框）。</span><br><span class="line">outerWidth(<span class="literal">true</span>)/outerHeight(<span class="literal">true</span>)  方法返回元素的宽度/高度（包括内边距、边框和外边距）。</span><br></pre></td></tr></table></figure>

<h3 id="scrollTop与scrollLeft"><a href="#scrollTop与scrollLeft" class="headerlink" title="scrollTop与scrollLeft"></a>scrollTop与scrollLeft</h3><ul>
<li>设置或者获取垂直滚动条的位置</li>
</ul>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 获取页面被卷曲的高度</span></span><br><span class="line">$(<span class="built_in">window</span>).scrollTop();</span><br><span class="line"><span class="comment">// 获取页面被卷曲的宽度</span></span><br><span class="line">$(<span class="built_in">window</span>).scrollLeft();</span><br></pre></td></tr></table></figure>

<p>案例：固定导航栏</p>
<h3 id="offset方法与position方法"><a href="#offset方法与position方法" class="headerlink" title="offset方法与position方法"></a>offset方法与position方法</h3><ul>
<li>offset方法获取元素距离document的位置，position方法获取的是元素距离有定位的父元素(offsetParent)的位置。</li>
</ul>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 获取元素距离document的位置,返回值为对象：&#123;left:100, top:100&#125;</span></span><br><span class="line">$(selector).offset();</span><br><span class="line"><span class="comment">// 获取相对于其最近的有定位的父元素的位置。</span></span><br><span class="line">$(selector).position();</span><br></pre></td></tr></table></figure>



<h2 id="jQuery事件机制"><a href="#jQuery事件机制" class="headerlink" title="jQuery事件机制"></a>jQuery事件机制</h2><ul>
<li>JavaScript中已经学习过了事件，jQuery对JavaScript事件进行了封装，增加并扩展了事件处理机制。jQuery不仅提供了更加优雅的事件处理语法，而且极大的增强了事件的处理能力。</li>
</ul>
<h3 id="jQuery事件发展历程-了解"><a href="#jQuery事件发展历程-了解" class="headerlink" title="jQuery事件发展历程(了解)"></a>jQuery事件发展历程(了解)</h3><p>简单事件绑定–bind事件绑定–delegate事件绑定–on事件绑定(推荐)</p>
<ul>
<li>简单事件注册</li>
</ul>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">click(handler)			单击事件</span><br><span class="line">mouseenter(handler)		鼠标进入事件</span><br><span class="line">mouseleave(handler)		鼠标离开事件</span><br></pre></td></tr></table></figure>

<p>缺点：不能同时注册多个事件</p>
<ul>
<li>bind方式注册事件</li>
</ul>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 第一个参数：事件类型</span></span><br><span class="line"><span class="comment">// 第二个参数：事件处理程序</span></span><br><span class="line">$(<span class="string">'p'</span>).bind(<span class="string">'click mouseenter'</span>, <span class="function"><span class="keyword">function</span>(<span class="params"></span>)</span>&#123;</span><br><span class="line">    <span class="comment">// 事件响应方法</span></span><br><span class="line">&#125;);</span><br></pre></td></tr></table></figure>

<p>缺点：不支持动态事件绑定</p>
<ul>
<li>delegate注册委托事件    通过父级元素给自己元素注册事件</li>
</ul>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 第一个参数：selector，要绑定事件的元素</span></span><br><span class="line"><span class="comment">// 第二个参数：事件类型</span></span><br><span class="line"><span class="comment">// 第三个参数：事件处理函数</span></span><br><span class="line">$(<span class="string">'.parentBox'</span>).delegate(<span class="string">'p'</span>, <span class="string">'click'</span>, <span class="function"><span class="keyword">function</span>(<span class="params"></span>)</span>&#123;</span><br><span class="line">    <span class="comment">// 为 .parentBox下面的所有的p标签绑定事件</span></span><br><span class="line">&#125;);</span><br></pre></td></tr></table></figure>

<p>缺点：只能注册委托事件，因此注册时间需要记得方法太多了</p>
<ul>
<li>on注册事件</li>
</ul>
<h3 id="on注册事件-重点"><a href="#on注册事件-重点" class="headerlink" title="on注册事件(重点)"></a>on注册事件(重点)</h3><ul>
<li>jQuery1.7之后，jQuery用on统一了所有事件的处理方法。</li>
<li>最现代的方式，兼容zepto(移动端类似jQuery的一个库)，强烈建议使用。</li>
</ul>
<p>on注册简单事件</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 表示给$(selector)绑定事件，并且由自己触发，不支持动态绑定。</span></span><br><span class="line">$(selector).on( <span class="string">'click'</span>, <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;&#125;);</span><br></pre></td></tr></table></figure>

<p>on注册事件委托</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 表示给$(selector)绑定代理事件，当必须是它的内部元素span才能触发这个事件，支持动态绑定</span></span><br><span class="line">$(selector).on( <span class="string">'click'</span>,<span class="string">'span'</span>, <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;&#125;);</span><br></pre></td></tr></table></figure>

<p>事件委托原理</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 事件委托的原理</span></span><br><span class="line"><span class="keyword">var</span> ul = <span class="built_in">document</span>.querySelector(<span class="string">'#ul'</span>);</span><br><span class="line">ul.onclick = <span class="function"><span class="keyword">function</span> (<span class="params">e</span>) </span>&#123;</span><br><span class="line">  <span class="comment">// console.log(e.target.tagName);</span></span><br><span class="line">  <span class="keyword">if</span> (e.target.tagName.toLowerCase() === <span class="string">'li'</span>) &#123;</span><br><span class="line">    <span class="built_in">console</span>.log(e.target);</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p><a href="https://www.cnblogs.com/liugang-vip/p/5616484.html" target="_blank" rel="noopener">js事件委托转自凌风之翼</a></p>
<p>on注册事件的语法：</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 第一个参数：events，绑定事件的名称可以是由空格分隔的多个事件（标准事件或者自定义事件）</span></span><br><span class="line"><span class="comment">// 第二个参数：selector, 执行事件的后代元素（可选），如果没有后代元素，那么事件将有自己执行。</span></span><br><span class="line"><span class="comment">// 第三个参数：data，传递给处理函数的数据，事件触发的时候通过event.data来使用（不常使用）</span></span><br><span class="line"><span class="comment">// 第四个参数：handler，事件处理函数</span></span><br><span class="line">$(selector).on(events[,selector][,data],handler);</span><br></pre></td></tr></table></figure>

<ul>
<li>通过源码查看 bind click delegate on 注册事件的区别</li>
</ul>
<h3 id="事件解绑"><a href="#事件解绑" class="headerlink" title="事件解绑"></a>事件解绑</h3><ul>
<li>unbind方式（不用）</li>
</ul>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">$(selector).unbind(); <span class="comment">// 解绑所有的事件</span></span><br><span class="line">$(selector).unbind(<span class="string">'click'</span>); <span class="comment">// 解绑指定的事件</span></span><br></pre></td></tr></table></figure>

<ul>
<li>undelegate方式（不用）</li>
</ul>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">$( selector ).undelegate(); <span class="comment">// 解绑所有的delegate事件</span></span><br><span class="line">$( selector).undelegate( <span class="string">'click'</span> ); <span class="comment">// 解绑所有的click事件</span></span><br></pre></td></tr></table></figure>

<ul>
<li>off方式（推荐）</li>
</ul>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 解绑匹配元素的所有事件</span></span><br><span class="line">$(selector).off();</span><br><span class="line"><span class="comment">// 解绑匹配元素的所有click事件</span></span><br><span class="line">$(selector).off(<span class="string">'click'</span>);</span><br></pre></td></tr></table></figure>

<h3 id="触发事件"><a href="#触发事件" class="headerlink" title="触发事件"></a>触发事件</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">$(selector).click(); <span class="comment">// 触发 click事件</span></span><br><span class="line">$(selector).trigger(<span class="string">'click'</span>);</span><br></pre></td></tr></table></figure>

<h3 id="jQuery事件对象"><a href="#jQuery事件对象" class="headerlink" title="jQuery事件对象"></a>jQuery事件对象</h3><p>jQuery事件对象其实就是js事件对象的一个封装，处理了兼容性。</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// screenX和screenY	对应屏幕最左上角的值</span></span><br><span class="line"><span class="comment">// clientX和clientY	距离页面左上角的位置（忽视滚动条）</span></span><br><span class="line"><span class="comment">// pageX和pageY	距离页面最顶部的左上角的位置（会计算滚动条的距离）</span></span><br><span class="line"></span><br><span class="line"><span class="comment">// event.keyCode	按下的键盘代码</span></span><br><span class="line"><span class="comment">// event.data	存储绑定事件时传递的附加数据</span></span><br><span class="line"></span><br><span class="line"><span class="comment">// event.stopPropagation()	阻止事件冒泡行为</span></span><br><span class="line"><span class="comment">// event.preventDefault()	阻止浏览器默认行为</span></span><br><span class="line"><span class="comment">// return false:既能阻止事件冒泡，又能阻止浏览器默认行为。</span></span><br></pre></td></tr></table></figure>



<h2 id="jQuery补充知识点"><a href="#jQuery补充知识点" class="headerlink" title="jQuery补充知识点"></a>jQuery补充知识点</h2><h3 id="链式编程"><a href="#链式编程" class="headerlink" title="链式编程"></a>链式编程</h3><ul>
<li>通常情况下，只有设置操作才能把链式编程延续下去。因为获取操作的时候，会返回获取到的相应的值，无法返回 jQuery对象。</li>
</ul>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">end(); <span class="comment">// 筛选选择器会改变jQuery对象的DOM对象，想要回复到上一次的状态，并且返回匹配元素之前的状态。</span></span><br></pre></td></tr></table></figure>

<h3 id="each方法"><a href="#each方法" class="headerlink" title="each方法"></a>each方法</h3><ul>
<li>jQuery的隐式迭代会对所有的DOM对象设置相同的值，但是如果我们需要给每一个对象设置不同的值的时候，就需要自己进行迭代了。</li>
</ul>
<p>作用：遍历jQuery对象集合，为每个匹配的元素执行一个函数</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 参数一表示当前元素在所有匹配元素中的索引号</span></span><br><span class="line"><span class="comment">// 参数二表示当前元素（DOM对象）</span></span><br><span class="line">$(selector).each(<span class="function"><span class="keyword">function</span>(<span class="params">index,element</span>)</span>&#123;&#125;);</span><br></pre></td></tr></table></figure>

<h3 id="多库共存"><a href="#多库共存" class="headerlink" title="多库共存"></a>多库共存</h3><ul>
<li>jQuery使用$作为标示符，但是如果与其他框架中的$冲突时，jQuery可以释放$符的控制权.(让权)</li>
</ul>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> c = $.noConflict();<span class="comment">// 释放$的控制权,并且把$的能力给了c</span></span><br></pre></td></tr></table></figure>

<h3 id="案例"><a href="#案例" class="headerlink" title="案例"></a>案例</h3><ul>
<li>五角星评分案例</li>
</ul>
<h2 id="插件"><a href="#插件" class="headerlink" title="插件"></a>插件</h2><h3 id="常用插件"><a href="#常用插件" class="headerlink" title="常用插件"></a>常用插件</h3><ul>
<li>弹出层插件 layer<ul>
<li><a href="https://github.com/sentsin/layer" target="_blank" rel="noopener">layer插件</a></li>
</ul>
</li>
<li>放大镜插件<ul>
<li><a href="http://www.jacklmoore.com/zoom/" target="_blank" rel="noopener">jQuery.zoom</a></li>
</ul>
</li>
<li>轮播图插件<ul>
<li><a href="http://sorgalla.com/jcarousel/" target="_blank" rel="noopener">http://sorgalla.com/jcarousel/</a></li>
<li><a href="https://github.com/OwlCarousel2/OwlCarousel2" target="_blank" rel="noopener">https://github.com/OwlCarousel2/OwlCarousel2</a></li>
</ul>
</li>
<li>图片懒加载插件<ul>
<li><a href="https://github.com/tuupola/jquery_lazyload" target="_blank" rel="noopener">jQuery.lazyload</a></li>
</ul>
</li>
<li>jQueryUI<ul>
<li>常用的2-3个功能演示</li>
</ul>
</li>
<li>查看jQuery插件的源码</li>
</ul>
<h3 id="自己探索插件"><a href="#自己探索插件" class="headerlink" title="自己探索插件"></a>自己探索插件</h3><ul>
<li><a href="https://github.com/aui/artDialog" target="_blank" rel="noopener">artDialog</a></li>
<li><a href="https://github.com/fat/zoom.js" target="_blank" rel="noopener">图片放大</a></li>
<li><a href="http://www.github.com" target="_blank" rel="noopener">github上搜索</a></li>
</ul>
<h2 id="jQuery插件开发"><a href="#jQuery插件开发" class="headerlink" title="jQuery插件开发"></a>jQuery插件开发</h2><ul>
<li>给jQuery增加方法的两种方式</li>
</ul>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">$.method = fn		静态方法</span><br><span class="line">$.fn.method = fn	实例方法</span><br></pre></td></tr></table></figure>

<ul>
<li>增加一个静态方法，实现两个数的和，插件</li>
</ul>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">(<span class="function"><span class="keyword">function</span> (<span class="params">$</span>) </span>&#123;</span><br><span class="line">  $.add = <span class="function"><span class="keyword">function</span> (<span class="params">a, b</span>) </span>&#123;</span><br><span class="line">    <span class="keyword">return</span> a + b;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;(jQuery))</span><br><span class="line"></span><br><span class="line">$.add(<span class="number">5</span>, <span class="number">6</span>);</span><br></pre></td></tr></table></figure>

<p>更多插件还要等待自己开发，不开发只用别人的不太好。jQuery基础的使用是必须要掌握的，还要多练习才能更熟练。后续会更新ajax。</p>

      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/jQuery-%E7%AC%94%E8%AE%B0/" rel="tag"># jQuery 笔记</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2020/05/07/08%E5%87%BD%E6%95%B0%E5%BC%8F%E7%BC%96%E7%A8%8B/" rel="next" title="函数式编程">
                <i class="fa fa-chevron-left"></i> 函数式编程
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2020/05/17/%E6%9C%8D%E5%8A%A1%E5%99%A8%E5%BC%80%E5%8F%91%E5%9F%BA%E7%A1%80/" rel="prev" title="服务器开发基础">
                服务器开发基础 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image"
                src="/images/agul1.png"
                alt="agul" />
            
              <p class="site-author-name" itemprop="name">agul</p>
              <p class="site-description motion-element" itemprop="description">天行健，君子以自强不息</p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/archives/%7C%7C%20archive">
              
                  <span class="site-state-item-count">13</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="/categories/index.html">
                  <span class="site-state-item-count">9</span>
                  <span class="site-state-item-name">分类</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-tags">
                <a href="/tags/index.html">
                  <span class="site-state-item-count">13</span>
                  <span class="site-state-item-name">标签</span>
                </a>
              </div>
            

          </nav>

          
            <div class="feed-link motion-element">
              <a href="/atom.xml" rel="alternate">
                <i class="fa fa-rss"></i>
                RSS
              </a>
            </div>
          

          

          
          

          
          

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#jQuery"><span class="nav-number">1.</span> <span class="nav-text">jQuery</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#jQuery简介"><span class="nav-number">1.1.</span> <span class="nav-text">jQuery简介</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#JavaScript库的概念"><span class="nav-number">1.1.1.</span> <span class="nav-text">JavaScript库的概念</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#jQuery的优点好处"><span class="nav-number">1.1.2.</span> <span class="nav-text">jQuery的优点好处</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#体验jQuery"><span class="nav-number">1.1.3.</span> <span class="nav-text">体验jQuery</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#jQuery中顶级对象"><span class="nav-number">1.1.4.</span> <span class="nav-text">jQuery中顶级对象</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#jQuery中页面加载事件"><span class="nav-number">1.1.5.</span> <span class="nav-text">jQuery中页面加载事件</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#jQuery对象和DOM对象"><span class="nav-number">1.2.</span> <span class="nav-text">jQuery对象和DOM对象</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#jQuery对象和DOM对象的区别"><span class="nav-number">1.2.1.</span> <span class="nav-text">jQuery对象和DOM对象的区别</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#DOM对象"><span class="nav-number">1.2.1.1.</span> <span class="nav-text">DOM对象</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#jQuery对象"><span class="nav-number">1.2.1.2.</span> <span class="nav-text">jQuery对象</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#区别"><span class="nav-number">1.2.1.3.</span> <span class="nav-text">区别</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#jQuery对象和DOM对象的相互转换"><span class="nav-number">1.2.2.</span> <span class="nav-text">jQuery对象和DOM对象的相互转换</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#选择器"><span class="nav-number">1.3.</span> <span class="nav-text">选择器</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#jQuery基本选择器"><span class="nav-number">1.3.1.</span> <span class="nav-text">jQuery基本选择器</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#jQuery层级选择器"><span class="nav-number">1.3.2.</span> <span class="nav-text">jQuery层级选择器</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#jQuery过滤选择器"><span class="nav-number">1.3.3.</span> <span class="nav-text">jQuery过滤选择器</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#jQuery筛选选择器-方法"><span class="nav-number">1.3.4.</span> <span class="nav-text">jQuery筛选选择器(方法)</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#jQuery操作样式"><span class="nav-number">1.4.</span> <span class="nav-text">jQuery操作样式</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#CSS操作"><span class="nav-number">1.4.1.</span> <span class="nav-text">CSS操作</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#class操作"><span class="nav-number">1.4.2.</span> <span class="nav-text">class操作</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#jQuery动画"><span class="nav-number">1.5.</span> <span class="nav-text">jQuery动画</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#三组基本动画"><span class="nav-number">1.5.1.</span> <span class="nav-text">三组基本动画</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#自定义动画"><span class="nav-number">1.5.2.</span> <span class="nav-text">自定义动画</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#动画队列与停止动画"><span class="nav-number">1.5.3.</span> <span class="nav-text">动画队列与停止动画</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#"><span class="nav-number">1.5.4.</span> <span class="nav-text"></span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#jQuery节点操作"><span class="nav-number">1.6.</span> <span class="nav-text">jQuery节点操作</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#创建节点"><span class="nav-number">1.6.1.</span> <span class="nav-text">创建节点</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#添加节点"><span class="nav-number">1.6.2.</span> <span class="nav-text">添加节点</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#清空节点与删除节点"><span class="nav-number">1.6.3.</span> <span class="nav-text">清空节点与删除节点</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#克隆节点"><span class="nav-number">1.6.4.</span> <span class="nav-text">克隆节点</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#-1"><span class="nav-number">1.6.5.</span> <span class="nav-text"></span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#jQuery操作属性"><span class="nav-number">1.7.</span> <span class="nav-text">jQuery操作属性</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#attr操作"><span class="nav-number">1.7.1.</span> <span class="nav-text">attr操作</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#prop操作"><span class="nav-number">1.7.2.</span> <span class="nav-text">prop操作</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#val-text-html"><span class="nav-number">1.7.3.</span> <span class="nav-text">val()&#x2F;text&#x2F;()html()</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#-2"><span class="nav-number">1.7.4.</span> <span class="nav-text"></span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#jQuery尺寸和位置操作"><span class="nav-number">1.8.</span> <span class="nav-text">jQuery尺寸和位置操作</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#width方法与height方法"><span class="nav-number">1.8.1.</span> <span class="nav-text">width方法与height方法</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#innerWidth-innerHeight-outerWidth-outerHeight"><span class="nav-number">1.8.2.</span> <span class="nav-text">innerWidth&#x2F;innerHeight&#x2F;outerWidth&#x2F;outerHeight</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#scrollTop与scrollLeft"><span class="nav-number">1.8.3.</span> <span class="nav-text">scrollTop与scrollLeft</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#offset方法与position方法"><span class="nav-number">1.8.4.</span> <span class="nav-text">offset方法与position方法</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#jQuery事件机制"><span class="nav-number">1.9.</span> <span class="nav-text">jQuery事件机制</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#jQuery事件发展历程-了解"><span class="nav-number">1.9.1.</span> <span class="nav-text">jQuery事件发展历程(了解)</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#on注册事件-重点"><span class="nav-number">1.9.2.</span> <span class="nav-text">on注册事件(重点)</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#事件解绑"><span class="nav-number">1.9.3.</span> <span class="nav-text">事件解绑</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#触发事件"><span class="nav-number">1.9.4.</span> <span class="nav-text">触发事件</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#jQuery事件对象"><span class="nav-number">1.9.5.</span> <span class="nav-text">jQuery事件对象</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#jQuery补充知识点"><span class="nav-number">1.10.</span> <span class="nav-text">jQuery补充知识点</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#链式编程"><span class="nav-number">1.10.1.</span> <span class="nav-text">链式编程</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#each方法"><span class="nav-number">1.10.2.</span> <span class="nav-text">each方法</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#多库共存"><span class="nav-number">1.10.3.</span> <span class="nav-text">多库共存</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#案例"><span class="nav-number">1.10.4.</span> <span class="nav-text">案例</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#插件"><span class="nav-number">1.11.</span> <span class="nav-text">插件</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#常用插件"><span class="nav-number">1.11.1.</span> <span class="nav-text">常用插件</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#自己探索插件"><span class="nav-number">1.11.2.</span> <span class="nav-text">自己探索插件</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#jQuery插件开发"><span class="nav-number">1.12.</span> <span class="nav-text">jQuery插件开发</span></a></li></ol></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2020</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">agul</span>

  
</div>


  <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> 强力驱动</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Pisces</a> v5.1.4</div>




        







        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  
    <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.4"></script>



  
  


  <script type="text/javascript" src="/js/src/affix.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/schemes/pisces.js?v=5.1.4"></script>



  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  












  





  

  

  

  
  

  

  

  

</body>
</html>
